package com.zmn.mcc.admin.controller.staff.staffreinstatement;


import com.zmn.common.utils.number.NumberUtil;
import com.zmn.mcc.model.entity.staff.McStaff;
import com.zmn.mcc.model.entity.staff.staffleaveoffice.StaffLeaveOffice;
import com.zmn.mcc.model.entity.staff.staffreinstatement.StaffReinstatementVO;
import com.zmn.mcc.services.interfaces.staff.StaffService;
import com.zmn.mcc.services.interfaces.staff.staffleaveoffice.StaffLeaveOfficeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 复职信息表基础查询Controller
 *
 * @author tanghongjun
 * @since 2020-10-22 15:53:17
 */
@RestController
@RequestMapping("/staff/staffreinstatement/")
public class StaffReinstatementListController extends StaffReinstatementBaseController {

    @Resource
    private StaffService staffService;

    @Resource
    private StaffLeaveOfficeService staffLeaveOfficeService;

    /**
     * 描述:跳转到员工复职信息页面
     *
     * @param staffId 员工ID
     * @return
     * @auther tanghongjun
     * @since 2020/10/23
     */
    @RequestMapping("/addEditView")
    @RequiresPermissions("/staff/staffreinstatement/addEditView.action")
    public ModelAndView addEditView(@RequestParam(value = "staffId", defaultValue = "0") Integer staffId) {

        StaffReinstatementVO staffReinstatement = new StaffReinstatementVO();
        if (NumberUtil.isPositiveInteger(staffId)) {
            staffReinstatement.setStaffId(staffId);

            McStaff staff = staffService.findByKey(staffId);
            if (Objects.nonNull(staff)) {
                staffReinstatement.setEntryTime(staff.getEntryTime());
            }

            StaffLeaveOffice staffLeaveOffice = staffLeaveOfficeService.findByStaffId(staffId);
            if (Objects.nonNull(staffLeaveOffice)) {
                staffReinstatement.setLastWorkTime(staffLeaveOffice.getLastWorkTime());
            }
        }

        ModelAndView mav = new ModelAndView("staff/staffreinstatement/detail");
        mav.addObject("staffReinstatement", staffReinstatement);

        return mav;
    }

}
